#include "automata2.h"
#include "testInputs.h"


void testInput(t_table * t)
{
     int i,result;
     void * aux;
     
     for(i=0;i<t->input.dim;i++)
     {
          result=validarInput(t,t->input.chains[i]);
          
          //Reserves some space in case empty chain was entered
          if((aux=(void *)realloc(t->input.chains[i],4))==NULL)
             error(1,"Could not allocate memory. Shame on you.");
          else
             t->input.chains[i]=aux;
          
          //Replace input chain with result
          if (result)
             strcpy(t->input.chains[i],"SI");
          else
             strcpy(t->input.chains[i],"NO");   
     }
     for(i=0;i<t->input.dim;i++)
     {
          printf("salida %s \n",t->input.chains[i]);
     }

}

int validarInput(t_table * t,char * string)
{
    int state,j=0,col;
    
    state=t->iniState;    
    
    while (string[j])
    {
          col=getSymIndex(t->alphabet,string[j]);
          state=t->transitions.data[state][col];
          if (state==-1)
             return 0;
          j++;
    }
    
    if (foundinFinalStates(t->finalStates,t->states.vec[state]))
       return 1;  
    
    return 0;    
}

int foundinFinalStates(t_int_vector array,int value)
{
    int i;
    for(i=0;i>array.dim;i++)
    {
      if (array.vec[i]==value)
         return 1;
    }  
    return 0;
}

